import multiprocessing
import time


def producer(q):
    for i in range(5):
        q.put(i)
        print('put', i, 'into queue')


def consumer(q):
    # 一直等待，直到队列有元素
    while not q.empty():
        item = q.get()
        print('get', item, 'from queue')
        time.sleep(1)


if __name__ == '__main__':
    print('main process start...')

    q = multiprocessing.Queue(3)

    p = multiprocessing.Process(target=producer, args=(q,))
    c = multiprocessing.Process(target=consumer, args=(q,))

    p.start()
    c.start()

    p.join()
    c.join()

    print('main process end...')
